<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="//cdn.bootcss.com/jquery/3.1.1/jquery.js"></script>
<title>微信支付</title>
</head>
<body>
<input id="payNo" type="hidden" value="${param.payNo}"></input>
<input id="payAmount"  type="hidden" value="${param.payAmount}"></input>
<input id="result"  type="hidden" value="${param.result}"></input>
	
</body>
	<script type="text/javascript" charset="UTF-8">
		var payNo = $('#payNo').val();
		var payAmount = $('#payAmount').val();
		var result = $('#result').val();
		var data={'returnCode':result,'payNo':payNo,'payAmount':payAmount};
		var notifyData = JSON.stringify(data);
		
		if(result == "CANCEL"){
			//alert("取消支付");
			$.ajax({
			type: "POST",
			url: "http://weixin.fosun-uhi.com/sinopay-web-weixinpay/sinopay/wechatPay/batchWechat.do",
			dataType:"json",
			data: {"payNo":payNo},
			success:function(data){
				var notifyUrl = data.notifyUrl;
				window.location.href = notifyUrl+"?data="+notifyData;
				},
				error:function(){
				}
			})
		}
		else{
				//ajax请求后台，查询商户对应回调地址
				$.ajax({
				type: "POST",
				url: "http://weixin.fosun-uhi.com/sinopay-web-weixinpay/sinopay/wechatPay/findMerchant.do",
				dataType:"json",
				data: {"payNo":payNo},
				success:function(data){
					var notifyUrl = data.notifyUrl;
					console.log(notifyUrl);
					window.location.href = notifyUrl+"?data="+notifyData;
				},
				error:function(){
					alert(error);
				}
			})
		}
	</script>
</html>